HAL RTC Typical use cases for migration ¶
This section provides information about the HAL RTC Typical use cases for migration.
HAL RTC calendar ¶
The main purpose of this use case is to configure the RTC calendar by setting the time and date, enabling accurate timekeeping for the application.
|
HAL1 Sequence Diagrams |
HAL2 Sequence Diagrams |
|---|---|
|
|
|
HAL RTC calendar use case ¶
|
HAL1 Example |
HAL2 Example |
|---|---|
RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0};
/** Initialize RTC Only */
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
hrtc.Init.SynchPrediv = RTC_SYNCH_PREDIV;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
hrtc.Init.BinMode = RTC_BINARY_NONE;
HAL_RTC_Init(&hrtc)
/** Initialize RTC and set the Time and Date */
sTime.Hours = 0x2;
sTime.Minutes = 0x0;
sTime.Seconds = 0x0;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD)
sDate.WeekDay = RTC_WEEKDAY_FRIDAY;
sDate.Month = RTC_MONTH_NOVEMBER;
sDate.Date = 0x6;
sDate.Year = 0x25;
HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD)
|
hal_rtc_config_t rtc_config;
hal_rtc_calendar_config_t rtc_calendar_config;
/* RTC and TAMP kernel clock enable */
HAL_RCC_RTC_SetKernelClkSource(HAL_RCC_RTC_CLK_SRC_LSE);
HAL_RCC_RTC_EnableKernelClock();
/* RTC and TAMP APB clock enable */
HAL_RCC_RTCAPB_EnableClock();
HAL_RTC_DisableWriteProtection();
HAL_RTC_EnterInitMode();
rtc_config.asynch_prediv = 0x7F;
rtc_config.synch_prediv = 0x00FF;
rtc_config.mode = HAL_RTC_MODE_BCD;
rtc_config.seconds_update = HAL_RTC_BCD_UPDATE_8BITS;
HAL_RTC_SetConfig(&rtc_config)
rtc_calendar_config.hour_format = HAL_RTC_CALENDAR_HOUR_FORMAT_24;
rtc_calendar_config.bypass_shadow_register = HAL_RTC_CALENDAR_SHADOW_REG_KEEP ;
HAL_RTC_CALENDAR_SetConfig(&rtc_calendar_config)
RtcTime.am_pm = HAL_RTC_TIME_FORMAT_AM_24H;
RtcTime.subsec = 0U;
RtcTime.microsec = 0U;
RtcTime.millisec = 0U;
RtcTime.hour = 2U;
RtcTime.min = 0U;
RtcTime.sec = 0U;
RtcDate.wday = HAL_RTC_WEEKDAY_FRIDAY ;
RtcDate.mon = HAL_RTC_MONTH_NOVEMBER ;
RtcDate.mday = 6U;
RtcDate.year = 25U;
HAL_RTC_CALENDAR_SetDateTime(&RtcDate, &RtcTime)
|
HAL RTC output ¶
The main purpose of this use case is to configure and manage the RTC output signals, including tampalarm and calibration outputs, and to enable or disable the RTC output as required by the application.
|
HAL1 Sequence Diagrams |
HAL2 Sequence Diagrams |
|---|---|
|
|
|
Related examples in HAL2 ¶
|
Example Name |
Description |
|---|---|
|
example_hal_rtc_calib_output_frequency |
Configuration of the calibration output frequency using the RTC HAL API. This example guides you through the different configuration steps by means of the RTC HAL API to configure a calibration output frequency. How to configure calibration output frequency using the RTC HAL API |
HAL RTC alarm ¶
The main purpose of this use case is to configure and manage the RTC alarm functionality, allowing the application to set alarms and handle alarm events using either interrupt mode or polling mode.
HAL RTC alarm use case ¶
|
HAL1 Example |
HAL2 Example |
|---|---|
RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0};
RTC_AlarmTypeDef sAlarm = {0};
/** Initialize RTC Only */
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
hrtc.Init.SynchPrediv = RTC_SYNCH_PREDIV;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
hrtc.Init.BinMode = RTC_BINARY_NONE;
HAL_RTC_Init(&hrtc);
/** Initialize RTC and set the Time and Date */
sTime.Hours = 0x2;
sTime.Minutes = 0x20;
sTime.Seconds = 0x0;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD);
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_DECEMBER;
sDate.Date = 0x7;
sDate.Year = 0x20;
HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD);
/** Enable the Alarm A */
sAlarm.AlarmTime.Hours = 0x2;
sAlarm.AlarmTime.Minutes = 0x20;
sAlarm.AlarmTime.Seconds = 0x30;
sAlarm.AlarmTime.SubSeconds = 0x56;
sAlarm.AlarmMask = RTC_ALARMMASK_NONE;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_WEEKDAY;
sAlarm.AlarmDateWeekDay = RTC_WEEKDAY_MONDAY;
sAlarm.Alarm = RTC_ALARM_A;
HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD);
|
hal_rtc_config_t rtc_config;
hal_rtc_calendar_config_t rtc_calendar_config;
hal_rtc_time_t rtc_time;
hal_rtc_date_t rtc_date;
hal_rtc_alarm_config_t alarm_config;
hal_rtc_alarm_date_time_t alarm_date_time_config;
/* Peripheral clock enable */
HAL_RCC_RTC_SetKernelClkSource(HAL_RCC_RTC_CLK_SRC_LSE);
HAL_RCC_RTC_EnableKernelClock();
HAL_RCC_RTCAPB_EnableClock();
HAL_RTC_DisableWriteProtection();
HAL_RTC_EnterInitMode();
rtc_config.asynch_prediv = 0x7F;
rtc_config.synch_prediv = 0x00FF;
rtc_config.mode = HAL_RTC_MODE_BCD;
rtc_config.seconds_update = HAL_RTC_BCD_UPDATE_8BITS;
HAL_RTC_SetConfig(&rtc_config)
HAL_RTC_ExitInitMode();
HAL_RTC_EnableWriteProtection();
alarm_config.auto_clear = HAL_ALARM_AUTO_CLEAR_DISABLE;
alarm_config.subsec_auto_reload = HAL_RTC_ALARM_SUBSECONDS_AUTO_RELOAD_DISABLE;
HAL_RTC_ALARM_SetConfig(HAL_RTC_ALARM_A, &alarm_config)
alarm_date_time_config.time.hour = 2U;
alarm_date_time_config.time.min = 20U;
alarm_date_time_config.time.sec = 30U;
alarm_date_time_config.time.subsec = 56U;
alarm_date_time_config.time.microsec = 0U;
alarm_date_time_config.time.millisec = 0U;
alarm_date_time_config.time.am_pm = HAL_RTC_TIME_FORMAT_AM_24H;
alarm_date_time_config.mask = HAL_RTC_ALARM_MASK_NONE;
alarm_date_time_config.subsec_mask = 0U;
alarm_date_time_config.mday_wday_selection = HAL_RTC_ALARM_DAY_TYPE_SEL_WEEKDAY;
alarm_date_time_config.wday_mday.wday = HAL_RTC_WEEKDAY_MONDAY ;
HAL_RTC_ALARM_SetDateTime(HAL_RTC_ALARM_A, &alarm_date_time_config)
/* Starts RTC alarm A in interrupt mode */
HAL_RTC_ALARM_Start(HAL_RTC_ALARM_A, HAL_RTC_ALARM_IT_ENABLE);
|
Related examples in HAL2 ¶
|
Example Name |
Description |
|---|---|
|
example_hal_rtc_alarm |
Configuration and generation of an RTC alarm using the RTC HAL API. This example guides you through the different configuration steps by means of the RTC HAL API to configure and generate an RTC alarm.How to configure and generate an RTC alarm using the RTC HAL API. |
HAL RTC timestamp ¶
HAL RTC timestamp enable pin source ¶
The main purpose of this use case is to configure and manage the RTC timestamp functionality, allowing the application to capture and retrieve the exact time and date of specific events. This can be achieved using either interrupt mode or polling mode, depending on the application’s requirements.
HAL RTC timestamp enable internal source ¶
The main purpose of this use case is to configure and manage the RTC timestamp functionality, including enabling internal and external timestamp sources. It allows the application to capture and retrieve the exact time and date of specific events using either interrupt mode or polling mode, depending on the application’s requirements.
Related examples in HAL2 ¶
|
Example Name |
Description |
|---|---|
|
example_hal_rtc_timestamp |
Configuration of the RTC HAL API to demonstrate the timestamp feature.This example guides you through the different configuration steps by means of the RTC HAL API to demonstrate the timestamp feature. |
|
example_hal_rtc_timestamp_tamper_source |
Configuration of the timestamp tamper source using the RTC HAL API. This example guides you through the different configuration steps by means of the RTC HAL API to configure a timestamp tamper source.How to configure timestamp tamper source using the RTC HAL API. |
HAL RTC wake-up timer ¶
The main purpose of this use case is to configure and manage the RTC wakeup timer, enabling the application to wake up periodically from low-power modes. The wakeup timer can be used in either interrupt mode or polling mode.
Related examples in HAL2 ¶
|
Example Name |
Description |
|---|---|
|
example_hal_rtc_wakeup_timer_from_standby |
How to periodically enter and wake up from STANDBY mode thanks to the RTC Wake-Up Timer (WUT). |
Note
For the TAMPER use cases, you can find the dedicated functions in the TAMP Driver.
This change is due to the specific concept to separate the RTC and TAMP drivers: Other HAL RTC changes
HAL TAMPER passive tampers ¶
HAL TAMPER internal tampers ¶
HAL TAMPER active tampers ¶
Related examples in HAL2 ¶
|
Example Name |
Description |
|---|---|
|
example_hal_tamp_active_detect |
The example illustrates the active tamper detection mode. This mode uses a continuous comparison between a tamper output and input generated by a pseudorandom number generator. In case of mismatch between the two signals, a tamper event is then triggered and the tamper backup registers are erased. |
HAL TAMPER monotonic counters ¶
|
HAL1 Sequence Diagrams |
HAL2 Sequence Diagrams |
|---|---|
|
|
|
HAL TAMPER Backup registers ¶
|
HAL1 Sequence Diagrams |
HAL2 Sequence Diagrams |
|---|---|
|
|
|
Related examples in HAL2 ¶
|
Example Name |
Description |
|---|---|
|
example_hal_tamp_erase_backup_registers |
The examples demonstrates the tamper detection feature, used to protect sensitive data from external attacks. It configures an external tamper in passive mode which is ultra-low power edge or level detection. Pressing the user button generates a tamper detection event which erases the TAMP backup registers, written at the beginning. |
HAL TAMPER device secrets ¶
|
HAL1 Sequence Diagrams |
HAL2 Sequence Diagrams |
|---|---|
|
|
|